const express = require('express');
const router = express.Router();

const MAO = require('multer-aliyun-oss')
const multer = require('multer')
const error = require('../../middleware/err-handle')
const auth = require('../../middleware/webAuth')
const taskValidata = require('../../validator/task')

const majorTask = require('../../controller/major')
const journal = require('../../controller/journal')

//上传文件夹配置
// function add0(m) {
//     return m < 10 ? '0' + m : m
// }
// var time = new Date();
// var y = time.getFullYear();
// var m = time.getMonth() + 1;
// var d = time.getDate();
// var h = time.getHours();
// m = add0(m)
// d = add0(d)
// h = add0(h)
// const upload = multer({
//     dest: 'uploads/' + y + '/' + m + '/' + d + '/'
// })

// 上传OSS配置
// const upload = multer({
//     storage: MAO({
//         config: {
//             region: 'oss-cn-shenzhen',
//             accessKeyId: 'LTAI5tG3pchVxj6pjqEpXuRe',
//             accessKeySecret: 'WnweDoDQAcfFyOMbrAkgzFpUdjxuXz',
//             bucket: 'baigei'
//         }
//     })
// })

// 上传OSS配置
// const upload = multer({
//     storage: MAO({
//         config: {
//             region: 'oss-cn-shenzhen',
//             accessKeyId: 'LTAI5tLBxQCbAVYHAjrRmBzz',
//             accessKeySecret: 'wUqVKZHAWdeEMp3fCN2rEU8uQcGoaP',
//             bucket: 'task-uploads'
//         }
//     })
// })

// 任务列表
router.get('/getTasks/:userId', auth(), majorTask.getTasks)
//获取任务(包括子任务)
router.get('/getTask/:taskId', auth(), majorTask.getTask)
// 分解任务
router.post('/submitTask', auth(), taskValidata.majorSummitTask, majorTask.submitTask, journal.journalCreate)
// 提交任务
router.post('/referTask/:taskId', auth(), taskValidata.majorReferTask, majorTask.referTask)
// 更新任务
router.put('/updataTask/:taskId', auth(), taskValidata.updataTask, majorTask.updataTask, journal.journalCreate)
// 删除任务
router.delete('/deleteTask/:taskId', auth(), taskValidata.majorDeleteTask, majorTask.deleteTask, journal.journalCreate)
// 删除单个文件
router.delete('/deleteFile/:taskId', auth(), majorTask.deleteFile)
// 删除多个文件
router.delete('/deleteAllFile/:taskId', auth(), majorTask.deleteAllFile)
// 下载文件
router.post('/download/:taskId', auth(), majorTask.download)
// 获取老师职位
router.post('/position', auth(), majorTask.position)
//错误处理中间键
router.use(error())

module.exports = router